%% Pattern demonstration test.
%%
-include_lib("ect/include/ect.hrl").

-class(pattern1).
-version(2).
?FIELDS(2, public, {a, b}).
%?FIELDS(1, private, {a, b}).
?FIELDS(2, public, {c, xxx = 1}).
-methods([transform/1, test0/1, upgrade/2]).

-export([dotest/0]).
-methods([dotest_2/1, method1/2, method2/2]).



%% Called from subclass pattern2, to test method
%% inheritance.
transform(This = #pattern1{c = "x"}) ->
    This#pattern1{c = "s"}.
    %This.

identity(A) ->
    A.

dotest_2(_) ->
    dotest().


method1(This, X) ->
    This#pattern1{xxx = X}.

method2(This, X) ->
    {This#pattern1{xxx = X}, This#pattern1.a}.

dotest() ->
    X = #pattern1{a = "p", b = "as", c = "s"},
    {_, #pattern1{a = A, c = C}} = {hellokitty, identity(X)},
    #pattern1{b = B} = X,
    list_to_atom(A++B++C).

test0(_) -> #pattern1{}.

upgrade(New, Old) ->
    case ectv_get_local_version(Old) of
    2 ->
        #pattern1{a = A, b = B, c = C, xxx = XXX} = Old,
        New#pattern1{a = A, b = B, c = C, xxx = XXX}
    end.